package fr.umlv.m2.uwp2011.web.client.professor;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.umlv.m2.uwp2011.web.client.Session;

public class ProfessorPlanningCourse extends Composite {

  /**
   * The planning panel.
   */
  private FlexTable planning;

  /**
   * The page panel.
   */
  private VerticalPanel pagePanel;
  /**
   * The main panel.
   */
  private VerticalPanel page;

  public ProfessorPlanningCourse(Session session) {
    /****************************** Widgets Creation ******************************/
    this.planning = new FlexTable();

    this.pagePanel = new VerticalPanel();
    this.page = new VerticalPanel();

    /*************************** Widgets initialization ***************************/    
    this.planning.setText(0, 1, "Lundi");
    this.planning.setText(0, 2, "Mardi");
    this.planning.setText(0, 3, "Mercredi");
    this.planning.setText(0, 4, "Jeudi");
    this.planning.setText(0, 5, "Vendredi");
    this.planning.setText(0, 6, "Samedi");

    int h = 0;
    for(int column=0; column<7; column++) {
      for(int i=8; i<20; i++) {
        for(int j=0; j<2; j++) {
          int row = i + h - 7;

          if(column == 0) {

            this.planning.setText(
                row, 
                column, ((j == 0)? i+"h00": i+"h30") +
                " - " + ((j == 0)? i+"h30": (i+1)+"h00")
            );

            this.planning.getFlexCellFormatter().setWidth(row, column, "40px");
            this.planning.getFlexCellFormatter().setHeight(row, column, "20px");
            this.planning.getFlexCellFormatter().setStyleName(
                row, column, "professorPlanningCourseTableFirstColumn"
            );
          } else {
            // Planning content without header and first column.
            
            this.planning.setWidget(row, column, null);
          }
          
          this.planning.getFlexCellFormatter().addStyleName(
              row, column, "professorPlanningCourseTableCells"
          );
          h++;
        }
        h--;
      }
      h = 0;
    }

    /******************************** Widgets style *******************************/
    this.planning.setWidth("746px");
    this.planning.addStyleName("professorPlanningCourseTable");

    // Table header.
    for(int column=1; column<7; column++) {
      this.planning.getFlexCellFormatter().setAlignment(
          0, column, HasAlignment.ALIGN_CENTER, HasAlignment.ALIGN_MIDDLE
      );
      
      this.planning.getFlexCellFormatter().setWidth(0, column, "50px");
      this.planning.getFlexCellFormatter().setHeight(0, column, "23px");
      this.planning.getFlexCellFormatter().addStyleName(0, column, "professorPlanningCourseTableCells");
    }

    this.pagePanel.setWidth("770px");

    /******************************** Page building *******************************/
    this.pagePanel.add(this.planning);
    this.page.add(this.pagePanel);

    initWidget(this.page);

    /******************************* Action handler *******************************/  
  }
}
